using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace xboxssbeatemup
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class EditorPanelEnemy : Microsoft.Xna.Framework.GameComponent
    {
        public System.Windows.Forms.ListBox initialStateLst;
        public System.Windows.Forms.ListBox attackTriggerLst;
        public System.Windows.Forms.ListBox zoneLst;
        public System.Windows.Forms.TextBox healthTxt;
        public System.Windows.Forms.TextBox healthMaxTxt;
        public System.Windows.Forms.TextBox magicTxt;
        public System.Windows.Forms.TextBox magicMaxTxt;
        public System.Windows.Forms.TextBox experienceTxt;
        public System.Windows.Forms.TextBox goldTxt;
        public System.Windows.Forms.TextBox attackTxt;
        public System.Windows.Forms.TextBox defenseTxt;
        public System.Windows.Forms.TextBox speedTxt;
        public int left = 0;
        public int top = 0;
        public bool hidden = false;
        public int statsLeft;
        public int statsTop;

        public EditorPanelEnemy(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            statsLeft = left + 970;
            statsTop = top - 100;

            initialStateLst = new System.Windows.Forms.ListBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(initialStateLst);
            initialStateLst.Items.Add("Attacking");
            initialStateLst.Items.Add("DrinkingAtBar");
            initialStateLst.Items.Add("Invisible");
            initialStateLst.Items.Add("Running");
            initialStateLst.Items.Add("Standing");
            initialStateLst.Items.Add("Swimming");
            initialStateLst.Left = left + 20;
            initialStateLst.Top = top + 24;
            initialStateLst.Width = 150;
            initialStateLst.SelectedValueChanged += new EventHandler(initialStateLst_SelectedValueChanged);

            attackTriggerLst = new System.Windows.Forms.ListBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(attackTriggerLst);
            attackTriggerLst.Items.Add("None");
            attackTriggerLst.Items.Add("PlayerAttack");
            attackTriggerLst.Items.Add("PlayerEnterZone");
            attackTriggerLst.Items.Add("PlayerInRange");
            attackTriggerLst.Left = left + 20 + 150 + 10;
            attackTriggerLst.Top = top + 24;
            attackTriggerLst.Width = 150;
            attackTriggerLst.SelectedValueChanged += new EventHandler(attackTriggerLst_SelectedValueChanged);

            healthTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(healthTxt);
            healthTxt.Left = statsLeft;
            healthTxt.Top = statsTop + 5;
            healthTxt.Width = 40;

            healthMaxTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(healthMaxTxt);
            healthMaxTxt.Left = statsLeft;
            healthMaxTxt.Top = statsTop + 5 + 25;
            healthMaxTxt.Width = 40;

            magicTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(magicTxt);
            magicTxt.Left = statsLeft;
            magicTxt.Top = statsTop + 5 + 50;
            magicTxt.Width = 40;

            magicMaxTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(magicMaxTxt);
            magicMaxTxt.Left = statsLeft;
            magicMaxTxt.Top = statsTop + 5 + 75;
            magicMaxTxt.Width = 40;

            experienceTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(experienceTxt);
            experienceTxt.Left = statsLeft;
            experienceTxt.Top = statsTop + 5 + 100;
            experienceTxt.Width = 40;

            goldTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(goldTxt);
            goldTxt.Left = statsLeft;
            goldTxt.Top = statsTop + 5 + 125;
            goldTxt.Width = 40;

            attackTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(attackTxt);
            attackTxt.Left = statsLeft;
            attackTxt.Top = statsTop + 5 + 150;
            attackTxt.Width = 40;

            defenseTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(defenseTxt);
            defenseTxt.Left = statsLeft;
            defenseTxt.Top = statsTop + 5 + 175;
            defenseTxt.Width = 40;

            speedTxt = new System.Windows.Forms.TextBox();
            System.Windows.Forms.Control.FromHandle(((Game1)this.Game).Window.Handle).Controls.Add(speedTxt);
            speedTxt.Left = statsLeft;
            speedTxt.Top = statsTop + 5 + 200;
            speedTxt.Width = 40;

            Hide();

            base.Initialize();
        }

        void initialStateLst_SelectedValueChanged(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).initialState
                = AnimationStateHelper.FromString(initialStateLst.SelectedItem.ToString());
        }
        void attackTriggerLst_SelectedValueChanged(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).attackTrigger
                = EventTriggerHelper.FromString(attackTriggerLst.SelectedItem.ToString());
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public void Hide()
        {
            initialStateLst.Visible = false;
            attackTriggerLst.Visible = false;
            healthTxt.Visible = false;
            healthMaxTxt.Visible = false;
            magicTxt.Visible = false;
            magicMaxTxt.Visible = false;
            experienceTxt.Visible = false;
            goldTxt.Visible = false;
            attackTxt.Visible = false;
            defenseTxt.Visible = false;
            speedTxt.Visible = false;
            hidden = true;
        }

        public void Show()
        {
            initialStateLst.Visible = true;
            attackTriggerLst.Visible = true;
            healthTxt.Visible = true;
            healthMaxTxt.Visible = true;
            magicTxt.Visible = true;
            magicMaxTxt.Visible = true;
            experienceTxt.Visible = true;
            goldTxt.Visible = true;
            attackTxt.Visible = true;
            defenseTxt.Visible = true;
            speedTxt.Visible = true;
            // Load data into editor fields if selected object is an Enemy
            if (((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject] != null
                && ((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject].GetType().ToString() == "xboxssbeatemup.Enemy")
            {
                initialStateLst.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).initialState.ToString();
                attackTriggerLst.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).attackTrigger.ToString();
                healthTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.health.ToString();
                healthMaxTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.healthMax.ToString();
                magicTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.magic.ToString();
                magicMaxTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.magicMax.ToString();
                experienceTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.experience.ToString();
                goldTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.gold.ToString();
                attackTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.attack.ToString();
                defenseTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.defense.ToString();
                speedTxt.Text = ((Enemy)(((Game1)this.Game).editor.eCreatedObjects[((Game1)this.Game).editor.eSelectedObject])).stats.speed.ToString();
            }
            hidden = false;
        }

        public void DrawText(SpriteBatch sb, SpriteFont font)
        {
            if (!hidden)
            {
                sb.DrawString(font, "Initial State:", new Vector2(left + 20, top + 5), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Attack Trigger:", new Vector2(left + 20 + 150 + 10, top + 5), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Health:", new Vector2(statsLeft - 80, statsTop + 5), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Health Max:", new Vector2(statsLeft - 80, statsTop + 5 + 25), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Magic:", new Vector2(statsLeft - 80, statsTop + 5 + 50), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Magic Max:", new Vector2(statsLeft - 80, statsTop + 5 + 75), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Experience:", new Vector2(statsLeft - 80, statsTop + 5 + 100), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Gold:", new Vector2(statsLeft - 80, statsTop + 5 + 125), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Attack:", new Vector2(statsLeft - 80, statsTop + 5 + 150), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Defense:", new Vector2(statsLeft - 80, statsTop + 5 + 175), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
                sb.DrawString(font, "Speed:", new Vector2(statsLeft - 80, statsTop + 5 + 200), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.100f);
            }
        }
    }
}